<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://www.ccut.edu.cn/saturn" prefix="saturn"%>
<%@page import="java.util.List"%>
<%@page import="edu.ccut.saturn.component.IMuneItemInfo"%>
<%@page import="edu.ccut.saturn.component.SaturnMenuManager"%>
<html>
<head>
<title>menu列表</title>
<%@ include file="/jsp/include/header/meta.jsp"%>
<%@ include file="/jsp/include/header/stylesheettag.jsp"%>
<%@ include file="/jsp/include/header/javascript.jsp"%>
<script language="javaScript">
function first(id,bundleName){
	menuForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.menu.impl::/menuModule/action/MenuItemUptoFirst.action?id="+id+"&bundleName="+bundleName+"&menuType=child";
	menuForm.submit();
}
function up(id,bundleName){
	menuForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.menu.impl::/menuModule/action/MenuItemUp.action?id="+id+"&bundleName="+bundleName+"&menuType=child";
	menuForm.submit();
}
function down(id,bundleName){
	menuForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.menu.impl::/menuModule/action/MenuItemDown.action?id="+id+"&bundleName="+bundleName+"&menuType=child";
	menuForm.submit();
}
function last(id,bundleName){
	menuForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.menu.impl::/menuModule/action/MenuItemDowntoLast.action?id="+id+"&bundleName="+bundleName+"&menuType=child";
	menuForm.submit();
}
function childMenus(id,bundleName){
	menuForm.action = "<%=request.getContextPath()%>/edu.ccut.saturn.manager.menu.impl/menuModule/page/childMenuItemList.jsp?id="+id+"&bundleName="+bundleName;
	menuForm.submit();
}
</script>
</head>

<body>
<% 
	String id = (String)request.getParameter("id");
	String bundleName = (String)request.getParameter("bundleName");
	String menuType = (String)request.getAttribute("menuType");
	if(id == null){
		id = (String)request.getAttribute("id");
	}
	if(bundleName == null){
		bundleName = (String)request.getAttribute("bundleName");
	}
	List childMenuItemList = SaturnMenuManager.getInstance().getMenuItemsOfRootMenuItem(id);
	if(menuType != null && menuType.equals("child")){
		List menuItems = SaturnMenuManager.getInstance()
					.getAllMenuItemInfos();

		String parentId = "";
		for(int i=0;i<menuItems.size();i++){
			IMuneItemInfo menuItem = (IMuneItemInfo)menuItems.get(i);
			if (menuItem.getId().equals(id)
					&& menuItem.getMenuInfo().getBundleSymbolicName()
							.equals(bundleName)) {

				parentId = menuItem.getParentId();
				break;
			}
		}
		if (!"".equals(parentId)) {
			childMenuItemList = SaturnMenuManager.getInstance()
					.getMenuItemsOfRootMenuItem(parentId);

		}
	}
	request.setAttribute("childMenuItemList",childMenuItemList);
 %>
<saturn:formBeans name="menuForm" title="子菜单列表"
		action="${pageContext.request.contextPath}/com.cchd.saturn.authority/authResourcePage/resourceList.jsp"
		method="post">
	<td>
		<saturn:table id="childMenu" value="${childMenuItemList}" item="var" isCursor="true"
				isPagepilot="true" percount="10">  
				<saturn:tableColumn title="菜单名">
				<% 
					IMuneItemInfo var = (IMuneItemInfo)pageContext.getAttribute("var"); 
					String varid = var.getId();
					String varbundlename = var.getMenuInfo().getBundleSymbolicName();
					int childListSize = SaturnMenuManager.getInstance().getMenuItemsOfRootMenuItem(varid).size();
					if(childListSize > 0) {
				%>
					<a href="#" onclick="childMenus('<saturn:out value="${var.id}"/>','<saturn:out value="${var.menuInfo.bundleSymbolicName}"/>')"><saturn:out value="${var.label}"/></a>
				<% }else{ %>
					<saturn:out value="${var.label}"/>
				<% } %>
				</saturn:tableColumn>              
				<saturn:tableColumn title="bundle名"><saturn:out value="${var.menuInfo.bundleSymbolicName}"/>
				</saturn:tableColumn>
				<saturn:tableColumn title="菜单路径"><saturn:out value="${var.path}"/></saturn:tableColumn>
				<saturn:tableColumn title="操作">
				<a href="#" onclick="first('<saturn:out value="${var.id}"/>','<saturn:out value="${var.menuInfo.bundleSymbolicName}"/>')">最上</a>
				|<a href="#" onclick="up('<saturn:out value="${var.id}"/>','<saturn:out value="${var.menuInfo.bundleSymbolicName}"/>')">上移</a>
				|<a href="#" onclick="down('<saturn:out value="${var.id}"/>','<saturn:out value="${var.menuInfo.bundleSymbolicName}"/>')">下移</a>
				|<a href="#" onclick="last('<saturn:out value="${var.id}"/>','<saturn:out value="${var.menuInfo.bundleSymbolicName}"/>')">最下</a>
				</saturn:tableColumn>
		</saturn:table>
	</td>
</saturn:formBeans>
</body>
</html>